package cn.t.converter.order;
import cn.t.core.converter.CoreDTOConverter;
import cn.t.dto.device.vo.OpenCloseDTO;
import cn.t.dto.order.OrderDTO;
import cn.t.model.device.DeviceDataDO;
import cn.t.model.order.OrderDO;
import cn.t.utils.DateUtil;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * 领料订单表(Order)dto转domain
 *
 * @author t
 * @since 2024-05-24 10:19:34
 */
@Mapper(componentModel = "spring")
public interface OrderDTOConverter extends CoreDTOConverter<OrderDTO, OrderDO> {
    OrderDO  do2Do(OpenCloseDTO openCloseDO);
    @Mapping(target = "id",ignore = true)
    OrderDO  addException2Do(DeviceDataDO deviceDataDO);
    default OrderDO  setOderDo(OpenCloseDTO openCloseDO){
        OrderDO orderDO = do2Do(openCloseDO);
        if (openCloseDO.getOpenRecordAt()!=null){
            orderDO.setGmtOpen(openCloseDO.getOpenRecordAt());
        }
        if (openCloseDO.getRecordAt()!=null){
            orderDO.setGmtClose(DateUtil.dateByStr(openCloseDO.getRecordAt()));
        }
        orderDO.setModifier(openCloseDO.getOperatorInfo());
        orderDO.setCreator(openCloseDO.getOperatorInfo());
        return orderDO;

    }
}

